package cn.edu.zut.DAO;

import cn.edu.zut.model.Student;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository(value = "bdi1")
public class StudentDAOImpl extends AbstractStudentDAO {

    @Override
    public void insertStudent(Student student) {
        String INSERT_STUDENT= "INSERT INTO stdent(id,name,sex,grand) VALUES(?,?,?)";
        Object[] args = { student.getId(), student.getName(),student.getsex("woman"),student.getgrand()};
        jdbcTemplate.update(INSERT_STUDENT, args);

    }

    @Override
    public void modifyStudent(Student student) {
        String MODIFY_STUDENT = "update student set id=?,name=?,sex=?,grand=?";
        Object[] args = { student.getId(), student.getName(),student.getsex("woman"),student.getgrand()};
        jdbcTemplate.update(MODIFY_STUDENT,args);
    }

    @Override
    public List<Student> queryAll() {
        String QUERY_ALL_STUDENT = "select * from student";
        RowMapper<Student> rowMapper=new BeanPropertyRowMapper<Student>(Student.class);
        students = jdbcTemplate.query(QUERY_ALL_STUDENT,rowMapper);
        return students;
    }
}
